//
//  AYAFNetworkTool.swift
//  iOSSinaWeb
//
//  Created by yws on 16/5/13.
//  Copyright © 2016年 yws. All rights reserved.
//

import UIKit
import AFNetworking

enum requestMethod: String {
    case GET = "GET"
    case POST = "POST"
}





class AYAFNetworkTool: NSObject {

    static let sharedInstance: AYAFNetworkTool = AYAFNetworkTool()
    
    private let afnManager: AFHTTPSessionManager = {
        let afn = AFHTTPSessionManager(baseURL: NSURL(string: "https://api.weibo.com/"))
        afn.responseSerializer.acceptableContentTypes?.insert("text/plain")
        return afn
    }()
    
    
    func request(method: requestMethod, URLString: String, parameters: AnyObject?, success: ((NSURLSessionDataTask, AnyObject?) -> Void)?, failure: ((NSURLSessionDataTask?, NSError) -> Void)? ) {
        
        if method == requestMethod.GET {
            
            afnManager.GET(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
        } else {
            afnManager.POST(URLString, parameters: parameters, progress: nil, success: success, failure: failure)
        }
    }
}
